/*
 * NetUtil.java
 * classes : com.ruint.core.utils.devices.NetUtil
 * @author ruint
 * V 1.0.0
 * Create at 2014-11-14 上午11:37:49
 */
package com.ruint.core.utils.devices;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;

/**
 * com.ruint.core.utils.devices.NetUtil
 * 
 * @author ruint <br/>
 *         create at 2014-11-14 上午11:37:49
 */
public class NetUtils {
  public static final int NETWORN_NONE = 0;
  public static final int NETWORN_WIFI = 1;
  public static final int NETWORN_MOBILE = 2;

  public static int getNetworkState(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    // Wifi
    State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    if (state == State.CONNECTED || state == State.CONNECTING) {
      return NETWORN_WIFI;
    }

    // 3G
    state = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
    if (state == State.CONNECTED || state == State.CONNECTING) {
      return NETWORN_MOBILE;
    }
    return NETWORN_NONE;
  }
}
